-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New pillar/master_tops saltclass module #42349
Conversation
@coredumb Very interesting! Let's start by getting these lint errors fixed up and then we'll do a full code review here. Thanks! |
Yep I saw the result, I only used flake8 on the code, I'll work that out :) |
addea3c
to
0b8fd68
Compare
@coredumb Could you please add a description of this new feature to the release notes? https://github.com/saltstack/salt/blob/develop/doc/topics/releases/oxygen.rst |
Sure no problem. Let me just improve examples with something that make sense first :) |
586a412
to
21ef791
Compare
Ok so I've made much better examples, and made modifications to oxygen.rst. Edit: Ok I've fixed the code blocks, let me know if documentation is clear enough |
21ef791
to
6e152ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I really love this addition, I think we should get some tests in before we accept it. When we add syntactic features like this to Salt they can be easily broken in the future without tests.
So in a nutshell, I want this in, but if we merge it without tests it WILL end up broken.
|
||
|
||
def ext_pillar(minion_id, pillar, *args, **kwargs): | ||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add some docs here, it does not need to be a lot, but just some info on expected data etc.
@thatch45 I'd be very happy to write tests for the modules if someone could point me in the right direction. About the documentation, indeed it needs some more informations, and maybe some more robust module initialization. I'll work on that. |
@coredumb that script would basically work, and it could be safely added to the unit tests. Take a look in here: |
@thatch45 As the modules are reading yaml files, is it OK to provide a test subset in the unit/pillar directory? |
Yes, although @cachedout might recall better where to put those for unit tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but needs one minor change in the release notes. We can make it when merging if there are no other objections.
doc/topics/releases/oxygen.rst
Outdated
---------------------------------------------- | ||
|
||
This module clones the behaviour of reclass (http://reclass.pantsfullofunix.net/), without the need of an external app, and add several features to improve flexibility. | ||
Saltclass let's you define your nodes from simple ``yaml`` files (``.yml``) through hierarchical class inheritance with the possibility to override pillars down the tree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be lets
instead of let's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops let me correct this one
6e152ab
to
8a9cf6f
Compare
f68bfde
to
1fae438
Compare
@coredumb You could put them here: https://github.com/saltstack/salt/tree/develop/tests/integration/files Also, we need a merge conflict resolved here. Thanks! |
@coredumb Did you see my comment above? |
@cachedout Sorry for not replying sooner, I got super busy on other tasks lately. |
@coredumb Totally understandable. Thanks for the quick reply! |
Hi @coredumb. Any update here? |
1fae438
to
04f5758
Compare
@cachedout Again sorry for the delay! I honestly have no idea how to run the test itself to ensure that it actually is valid... I've looked around the documentation but I must be blind... |
0a42ff4
to
c2d3409
Compare
@cachedout OK sorry for not being able to find the documentation sooner...
|
1b565cf
to
6340436
Compare
6340436
to
139e065
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments, suggesting some features
|
||
|
||
# Renders jinja from a template file | ||
def render_jinja(_file, salt_data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possibe to configure jinja the same way as for SLS/Pillars.
Especially I am talking about the jinja line statements setup. See #42930 for details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be too hard to implement
if sub_init in l_files: | ||
return render_yaml(sub_init, salt_data) | ||
|
||
log.warning('{0}: Class definition not found'.format(_class)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We recently added to original "reclass" the feature to ignore some missing classes: https://github.com/salt-formulas/reclass/blob/master/reclass/core.py#L103
At first it might sound strange, the use case is for bootstrap. We ship metadata classes in the formulas. While the node refer to these it's pillar can't be valid until all the dependecy formulas are installed. As we install salt formulas with salt according to "reclass" pillar we have chicken-egg problem.
Way to resolve is quite simple:
- preinstall only formulas required to bootstrap salt master (in our case salt,linux,git,reclass)
- allow ignoring some missing classes with specific pattern (aka service.xyz.*)
- apply core slat master states (that will install all dependencies according a pillar/model)
- update configuration to fail on any missing class
- finish w/highstate/orchestrate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah bootstrapping usually requires to preinstall something, and saltclass doesn't cut it ;)
I have a question, will it load map.jinja (defaults options used to render it) if it's found in saltclass root? |
It will not load any map.jinja. If you want something to be loaded it must be so as a class. |
@thatch45 @cachedout Do I still need to fix something for the merge to happen? |
I'd like to get @thatch45 to take another swing by here and re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good now!
@olivier-mauras don't you think saltclass should be also directly compatible with reclass yaml files? For example if the |
@bbinet I must admit this is something I didn't even think about as I thought that a simple grep/sed onelining was easy enough to try out |
Backward compatibility would be nice, but nothing is easy and as saltclass has a lot new features and it may not play well in your current ecosystem anyway. I rather prefer not to look back. @bbinet I build the images with to test saltclass with that grep/sed employed against my formulas and it works great. https://github.com/epcim/docker-salt-formulas/blob/master/DockerMake.yml
BTW folks, Saltclass return reference string '${refference:that:is:not:defined:xyz}' instead of throw an error. Is that supposed to be a feature? IMHO That may case rendering nonsense in system critical files. |
@epcim Yes this is expected because I hate to see the pillar crash because of a typo. |
Well worth to print a warning at least. Replace it with empty string might be an option as well but then we lose a track of its name in the final output. Possibly have this behaviour configurable. And have the option to throw an error during CI, test=true run?, for example. |
Imho, pillar should crash because of a typo. Same with missing classes. Otherwise, this can easily lead to silent failures. Please provide a way to enable strict checks by default. |
Is it really necessary to rescan the directory tree on each
I can't say this is the only source of performance regression, but salt is definitely slower: Salt 2017.7.0, reclass:
Salt 2018.3.1, saltclass:
|
From my testings over the same dataset of 27 Class files, reclass takes 0.588s to process against 0.181s for the saltclass code. |
Is there any way to combine |
What does this PR do?
It provides a new pillar/master_tops module called
saltclass
.This module clones the behaviour of reclass, without the need of an external app, and add a couple of features to improve flexibility.
Features
applications
=>states
parameters
=>pillars
for i in $(grep -r -e applications: -e parameters: -l <your_reclass_path>); do sed -i 's/applications:/states:/g;s/parameters:/pillars:/g' $i; done
__opts__
__salt__
__grains__
__pillars__
minion_id
^
character (see examples)${}
with possibility to escape them if needed\${}
(see examples)Configuration
Examples
Basic jinja + grains example
List merge example
Variables expansion
An example subset of datas is available here: http://git.mauras.ch/salt/saltclass/src/master/examples
Although useless it gives a pretty good idea how to layout your class hierarchy.
Integrated documentation is pretty scarse at the moment, I'll try to improve that ASAP